package com.xiaozheng.ui;

import com.xiaozheng.dao.AccountDao;
import com.xiaozheng.service.AccountService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Package: com.xiaozheng.coupling.ui
 * @ClassName: ClientDecoupling
 * @Author: 小政同学    QQ:xiaozheng666888@qq.com
 * @CreateTime: 2020/9/19 19:07
 * @What_is_this_file_for: 模拟表现层，用于调用业务层
 * @Description: 描述
 */
public class ClientDecoupling {
    /**
     * 获取spring的Ioc核心容器，并根据id获取对象
     * @param args
     */
    public static void main(String[] args) {
        //AccountService as = new AccountServiceImpl();
        //AccountService as = (AccountService) BeanFactory.getBean("accountService");
        //1.获取核心容器对象
            //立即加载
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
            //延时加载
        //Resource resource = new ClassPathResource("bean.xml");
        //BeanFactory ac = new XmlBeanFactory(resource);
        //根据id获取bean对象
        AccountDao ad = ac.getBean("accountDao", AccountDao.class);
        //输出对象创建
        System.out.println(ad);

        AccountService as = (AccountService) ac.getBean("accountService");
        as.saveAccountService();
        System.out.println(as);

        AccountService asi = (AccountService) ac.getBean("tesAccoutServiceImpl");
        asi.saveAccountService();
        System.out.println(asi);

        AccountService casi = (AccountService) ac.getBean("complexAccountServiceImpl");
        casi.saveAccountService();
        System.out.println(casi);


        ac.close();

        //as.saveAccountService();

    }

}
